<template>
	<view>
		<view class="header">
			<view class="title">退款订单</view>
			<view class="bottonGroup">
				<view class="botton focus">全部</view>
			</view>
		</view>

		<view class="content">
			<scroll-view scroll-y="true" @scrolltolower="loadData" class="scroll-view">
				<view v-for="(item, index) in refundList" :key="index">
					<view class="customer-card">
						<view class="card-header">
							<view class="user-info">
								<image :src="item.avatar" class="avatar"></image>
								<view class="user-detail">
									<text class="nickname">{{item.nickname}}</text>
									<text class="refund-no">退款单号：{{item.refundNo}}</text>
								</view>
							</view>
							<text class="status">已退款</text>
						</view>
						<view class="card-content">
							<view class="info-row">
								<text class="label">姓名</text>
								<text class="value">{{item.name || '--'}}</text>
							</view>
							<view class="info-row">
								<text class="label">手机号</text>
								<text class="value">{{item.phone || '--'}}</text>
							</view>
							<view class="info-row">
								<text class="label">新老客</text>
								<text class="value">{{item.isNew ? '新客' : '老客'}}</text>
							</view>
							<view class="info-row">
								<text class="label">支付时间</text>
								<text class="value">{{item.payTime || '--'}}</text>
							</view>
							<view class="info-row">
								<text class="label">参与时间</text>
								<text class="value">{{item.joinTime || '--'}}</text>
							</view>
							<view class="info-row">
								<text class="label">溯源</text>
								<text class="value">{{item.source || '--'}}</text>
							</view>
							<view class="info-row">
								<text class="label">上级</text>
								<text class="value">{{item.parent || '--'}}</text>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import * as api from '@/api/staff'
	import storage from '@/utils/storage'
	
	export default {
		data() {
			return {
				activityId: 0,
				refundList: [],
				page: 1,
				pageSize: 20,
				loading: false,
				hasMore: true
			}
		},
		onLoad() {
			this.activityId = storage.get('activityId')
			this.loadData()
		},
		methods: {
			loadData() {
				if (this.loading || !this.hasMore) return
				this.loading = true
				
				api.getRefundOrders({
					activity_id: this.activityId,
					page: this.page,
					limit: this.pageSize
				}).then(res => {
					const list = res.data.map(item => ({
						refundNo: item.refund_no,
						nickname: item.user_nickname,
						avatar: item.avatar_url,
						name: item.name,
						phone: item.phone,
						isNew: item.customer_type === '新客',
						payTime: item.pay_time === '0000-00-00 00:00:00' ? '--' : item.pay_time,
						joinTime: item.create_time,
						source: item.clerk_nickname || '--',
						parent: item.recom_nickname || '--'
					}))
					
					if (this.page === 1) {
						this.refundList = list
					} else {
						this.refundList = [...this.refundList, ...list]
					}
					this.hasMore = list.length === this.pageSize
					this.page++
				}).finally(() => {
					this.loading = false
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #F6F7FB;
	}

	.header {
		background-color: #FFAC3E;
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 250rpx;
		border-radius: 0rpx 0rpx 20rpx 20rpx;
	}

	.header > .title {
		color: #fff;
		padding: 30rpx;
		font-size: 40rpx;
		font-weight: bold;
	}

	.header > .bottonGroup {
		width: 100%;
		position: initial;
		display: inline-table;
		text-align: center;
		margin-top: 0px;
	}

	.header > .bottonGroup view {
		font-size: 28rpx;
		float: left;
		padding: 5px 10px;
		margin-right: 5px;
		margin: 0px 0px 10px 10px;
		z-index: 999;
	}

	.header > .bottonGroup .botton {
		color: #FFFFFF;
	}

	.header > .bottonGroup .focus {
		border-bottom: 3px solid #FFFFFF;
		color: #FFFFFF;
	}

	.content {
		margin-top: 195rpx;
		padding: 20rpx;
		box-sizing: border-box;
	}

	.scroll-view {
		height: calc(100vh - 195rpx);
	}

	.customer-card {
		width: 100%;
		border-radius: 30rpx;
		background-color: #fff;
		margin-bottom: 20rpx;
		padding: 20rpx 25rpx;
		box-sizing: border-box;
	}

	.card-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-bottom: 20rpx;
		border-bottom: 1px solid #f5f5f5;
	}

	.user-info {
		display: flex;
		align-items: center;
	}

	.user-detail {
		margin-left: 20rpx;
		display: flex;
		flex-direction: column;
	}

	.avatar {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
	}

	.nickname {
		font-size: 32rpx;
		color: #333;
		margin-bottom: 8rpx;
	}

	.refund-no {
		font-size: 24rpx;
		color: #999;
	}

	.status {
		font-size: 28rpx;
		color: #FF6B6B;
	}

	.card-content {
		padding-top: 20rpx;
	}

	.info-row {
		display: flex;
		justify-content: space-between;
		margin-bottom: 16rpx;
	}

	.info-row:last-child {
		margin-bottom: 0;
	}

	.label {
		color: #666;
		font-size: 28rpx;
	}

	.value {
		color: #333;
		font-size: 28rpx;
		max-width: 60%;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
</style> 